class Node:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def solve(head, delete):
    pre = Node()
    pre.next = head
    cur = head
    while cur and cur != delete:
        pre = pre.next
        cur = cur.next
    pre.next = cur.next
    return head

def construct(lst):
    dummy = Node()
    cur = dummy
    for i in lst:
        new_node = Node(val=i) #不要和类同名
        cur.next = new_node
        cur = cur.next
    return dummy.next

def print_val(head):
    cur = head
    while cur:
        print(cur.val, end=' ')
        cur = cur.next
    print()  # 为了在末尾添加换行

lst = list(map(int, input().split()))
k = int(input())
head = construct(lst)
cur = head
for _ in range(k):
    if cur is not None:
        cur = cur.next
    else:
        break
if cur is not None:
    head = solve(head, cur)
print_val(head)